<template>
    <div class="app-container" style="padding:20px">
        <el-card>
            <FormTopBar title="工作请示单" :flowInsId="form.flowInsId" :taskId="taskId" :businessId="form.id"
                        :billType="form.billType" @submitForm="submitForm"></FormTopBar>
        </el-card>
        <FlowInfoCard  :id="form.id+''" :billType="form.billType" :flowInsId="form.flowInsId">
            <!-- 添加或修改员工入职对话框 -->
            <el-form ref="form" :model="form" :rules="rules" label-width="120px" :disabled="readonly">
                <el-card class="top15">
                    <div slot="header" class="clearfix">
                        <span>基础信息</span>
                        <span style="float: right" v-if="form.id!=undefined">单据编号：{{form.billCode}}</span>
                    </div>
                    <el-form-item label="申请标题" prop="applyTitle">
                        <el-input v-model="form.applyTitle" placeholder="请输入申请标题"/>
                    </el-form-item>
                    <el-form-item label="请示内容">
                        <editor v-model="form.content" :min-height="192"/>
                    </el-form-item>
                    <el-form-item label="备注" prop="remark">
                        <el-input v-model="form.remark" type="textarea" :rows="5" placeholder="请输入内容"/>
                    </el-form-item>
                    <el-form-item label="附件" prop="url">
                        <file-upload v-model="form.url"/>
                    </el-form-item>
                </el-card>
            </el-form>
        </FlowInfoCard>
    </div>
</template>

<script>
import FlowInfo from "@/views/workflow/flow/flowInfo";
import {listWorkRequest, getWorkRequest, delWorkRequest, addWorkRequest, updateWorkRequest} from "@/api/oa/workRequest";
import FormTopBar from "@/views/workflow/common/formTopBar"
import FlowInfoCard from "@/views/workflow/common/flowinfoCard";
export default {
    name: "TicketApplyForm",
    components:{FlowInfo,FormTopBar,FlowInfoCard},
    data() {
        return {
            // 表单参数
            form: {
            },
            showFlowInfo:false,
            taskId:'',
            // billType:'',
            readonly:false,
            // 表单校验
            rules: {
                applyTitle: [
                    {required: true, message: "申请标题不能为空", trigger: "blur"}
                ],
            },
            showCommitDialog:false,
            commitType:"",
        };
    },
    provide(){
        return {
            addCcedList:this.addCcedList
        }
    },
    created() {
        //单据的id主键
        const formId = this.$route.params && this.$route.params.formId;
        //单据的类型
        const billType = this.$route.params && this.$route.params.billType;
        const taskId = this.$route.query && this.$route.query.taskId;
        const readonly = this.$route.query && this.$route.query.readonly;
        if(billType){
            this.form.billType = billType;
        }
        if(taskId){
            this.taskId = taskId;
        }
        if("1"==readonly){
            this.readonly = true;
        }
        if(formId){
            this.form.id = formId;
            this.getDetailData(formId);

        }
    },
    mounted() {
    },
    methods: {
        //  获取单据信息
        getDetailData(id) {
            getWorkRequest(id).then(response => {
                this.form = response.data;
            });
        },
        /** 提交按钮 */
        submitForm() {
            console.log(this.form.timeRange)
            console.log("billType= "+ this.form.billType);
            if(this.form.timeRange && this.form.timeRange.length>0){
                this.form.startTime = this.form.timeRange[0];
                this.form.endTime = this.form.timeRange[1];
            }

            this.$refs["form"].validate(valid => {
                if (valid) {
                    if (this.form.id != null) {
                        updateWorkRequest(this.form).then(response => {
                            this.$modal.msgSuccess("修改成功");
                            this.closeThisPage();
                        });
                    } else {
                        addWorkRequest(this.form).then(response => {
                            this.$modal.msgSuccess("保存成功");
                            this.closeThisPage();
                        });
                    }
                }
            });
        },
        closeThisPage(){
            this.$tab.closeOpenPage({ path: "/work/workRequest",query: {billType:this.form.billType}});
        },
        // 创建单据时候，选择了抄送人
        addCcedList(ccedList){
            this.form.ccedList = ccedList;
            console.log("回填抄送人")
            console.log(this.form)
        }
    }
};
</script>
